home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.09 Sep 91 / Generic Source ƒ / DebugAids.c next >
Encoding:
C/C++ Source or Header  |  1991-06-17  |  1.5 KB  |  80 lines  |  [TEXT/KAHL]

  1. #pragma mark Header
  2. /***************************/
  3. /* DebugAids.c
  4.     This file contains some generic debugging aids
  5.     6/5/91 - created by Kirk Chase */
  6. /***************************/
  7.  
  8. #pragma mark #includes
  9. #include <stdio.h>
  10. #include <signal.h>
  11. #include <errno.h>
  12. #include <assert.h>
  13.  
  14. #include "DebugAids.h"
  15.  
  16. #pragma mark #defines
  17. #ifndef TRUE
  18. #define TRUE (1)
  19. #define FALSE (0)
  20. #endif
  21.  
  22. #pragma mark Externals
  23. extern jmp_buf env;
  24.  
  25. #pragma mark Static Globals
  26. static int __userAbort = FALSE;
  27.  
  28. /* CheckOptionAbort() 
  29.     Routine to look for option key pressed.
  30.     returns TRUE if there was, FALSE if none */
  31. CheckOptionAbort(void)
  32. {
  33. #ifdef THINK_C
  34. KeyMap debugKeys;
  35.  
  36. GetKeys(&debugKeys);
  37. if (debugKeys.Key[1] & 0x4) {
  38.     SigHandler(SIGINT);
  39.     return(TRUE);
  40.     }
  41.     
  42. #endif
  43.  
  44. return(FALSE);
  45. }
  46.  
  47. /* UserAbort() 
  48.     Routine to set user abort flag.
  49.     jumps to signal handling software sending SIGINT */
  50. void UserAbort(int sig)
  51. {
  52. __userAbort = TRUE;
  53. longjmp(env, SIGINT);
  54. }
  55.  
  56. /* SigHandler(int sig)
  57.     Sets up signals (sig=0) or handles them (sig=anything) */
  58. SigHandler(int sig)
  59. {
  60. switch (sig) {
  61.     case 0: /* set up signals */
  62.         assert(signal(SIGINT, &UserAbort) != SIG_ERR);
  63.         break;
  64.     case SIGINT: /* User abort, cmd-. */
  65.         signal(SIGINT, &UserAbort);
  66.         __userAbort = FALSE;
  67.         #ifdef DEBUG
  68.         fprintf(stderr,"\n***User Interrupt***\n");
  69.             #ifdef DEBUGGER
  70.             DebugStr("\p***User Interrupt***");
  71.             #endif
  72.         #endif
  73.         break;
  74.     default: /* unknown signal */
  75.         #ifdef DEBUG
  76.         fprintf(stderr,"\n***Unknown Signal***%d\n", sig);
  77.         #endif
  78.         break;
  79.     }
  80. }